<template>
	<view class="container">
		<view class="input_box ">
			<view class="title hh">收货人</view>
			<input type="text" v-model="name" placeholder="请输入收货人姓名">
		</view>
		<view class="input_box">
			<view class="title">手机号码</view>
			<input type="number" v-model="mobile" maxlength="11" placeholder="请输入收货人手机号码">
		</view>
		<view class="input_box" @click="show = true">
			<view class="title">所在地区</view>
			<input type="number" v-model="city" placeholder="请输入收货人所在地区" disabled="">
			<!-- <view style="display: flex;align-items: center;justify-content: center;" @click.stop="mapClick">
				<u-icon name="map" color="#ff3b3b" size="40"></u-icon>
				定位
			</view> -->
		</view>
		<view class="input_box">
			<view class="title">详细地址</view>
			<input type="text" v-model="address" placeholder="请填写详细地址如：街道、门牌号等">
		</view>
		<view class="bottom">
			<view class="title">设置默认地址</view>
			<view class="btn_S">
				<view class="text">提醒：每次下单时会使用该地址,实际下单前请确认好地址在下单哦!</view>
				<u-switch v-model="checked" active-color="#ff3b3b"></u-switch>
			</view>
		</view>
		<view class="sebtns" @click="addbank">保存并使用</view>
		<u-picker v-model="show" mode="region" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				address: '',
				mobile: '',
				city: '',
				checked: false,
				id: null,
				show: false,
				province: '',
				citys: '',
				area: ''
			}
		},
		onLoad() {
			// this.getArea()
		},
		methods: {
			getArea() {
				this.$u.api.getArea().then(res => {

				})
			},
			mapClick() {
				uni.chooseLocation({
					success: res => {
						console.log(res)
						this.city = res.address
					}
				});
			},
			confirm(e) {
				this.city = e.province.label + '-' + e.city.label + '-' + e.area.label
				this.province = e.province.label
				this.citys = e.city.label
				this.area = e.area.label
			},
			addbank() {
				let isDefault = ''
				if (this.checked) {
					isDefault = '1'
				} else {
					isDefault = '0'
				}
				if (this.name == '') {
					this.$u.toast('请输入收货人姓名')
					return
				} else if (this.mobile == '') {
					this.$u.toast('请输入收货人手机号码')
					return
				} else if (this.city == '') {
					this.$u.toast('请输入收货人所在地区')
					return
				} else if (this.address == '') {
					this.$u.toast('请填写详细地址')
					return
				} else {
					let model = {
						// id: this.id,
						username: this.name,
						telephone: this.mobile,
						adrdetail: this.address,
						is_def: isDefault,
						province: this.province,
						city: this.citys,
						county: this.area,
					}
					this.$allApi.addAddress(model).then(res => {
						this.$u.toast('添加地址成功')
						setTimeout(() => {
							this.$backTo(1)
						}, 2000)
					})
					// this.$u.api.addUserBank({
					// 	real_name: this.name,
					// 	bank_name: this.bankName,
					// 	card_no: this.bankNumber,
					// 	mobile: this.mobile
					// }).then(res => {
					// 	this.$u.toast('添加银行卡成功')
					// 	setTimeout(() => {
					// 		this.$backTo(1)
					// 	}, 2000)
					// })
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.bottom {
		margin-top: 20rpx;
		background: #fff;
		padding: 20rpx;
		color: #666;
		line-height: 1.8;

		.title {
			font-size: 30rpx;
		}

		.btn_S {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.text {
				font-size: 24rpx;
				flex: 1;
				padding-right: 20rpx;
			}
		}
	}

	.container {
		min-height: 100vh;
		background: #f6f6f6;
	}

	.input_box {
		display: flex;
		align-items: center;
		height: 110rpx;
		border-bottom: 1px solid #eee;
		padding: 20rpx;
		background: #fff;

		.title {}

		.hh {
			letter-spacing: 0.5em;
			/*如果需要y个字两端对齐，则为(x-y)/(y-1),这里是（4-3）/(3-1)=0.5em */
			margin-right: -0.5em;
			/*同上*/
		}

		input {
			flex: 1;
			padding-left: 30rpx;
		}
	}

	.sebtns {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		background: #ff3b3b;
		color: #fff;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 110rpx;
		padding-bottom: calc(-30rpx + env(safe-area-inset-bottom));
	}
</style>
